package module.service.account.impl;

import com.aliyuncs.exceptions.ClientException;
import module.common.EnumExceptionType;
import module.entity.User;
import module.entity.User_role;
import module.service.account.SignUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import module.exception.RRException;
import module.service.BaseService;
import module.util.PasswordUtil;


@Service
@Transactional
public class SignUpServiceImpl extends BaseService implements SignUpService {

    @Override
    public void signUp(String username,String password) {

        User user = User.builder().username(username).build();

        //查看用户是否已存在
        if (userMapper.getUserByUsername(username) != null)
            throw new RRException(EnumExceptionType.USER_ALREADY_EXIST);

        user.setPassword(PasswordUtil.convert(password));

        //注册
        if (userMapper.insertUser(user.getUsername(),user.getPassword()) != 1) {
            throw new RRException(EnumExceptionType.SYSTEM_INTERNAL_ANOMALY);
        }
    }
}
